import yaml
from utils.enums import FilePath


class YAML:
    #### 开发环境
    # file_path = FilePath.YAML_PATH_DEV.value

    #### 生产环境
    file_path = FilePath.YAML_PATH_PRODUCT.value

    @staticmethod
    def ReadYaml(file_path):
        with open(file_path, 'r', encoding='utf-8') as file:
            config = yaml.safe_load(file)
        return config

    @staticmethod
    def ReadRoot(root):
        if root == 'mysql':
            file = YAML.ReadYaml(YAML.file_path).get(root, [])
            return [info for info in file]
        if root == 'redis':
            file = YAML.ReadYaml(YAML.file_path).get(root)
            temp_keys = [k for k, v in file.items() if v == 'None' or v is None]
            for key in temp_keys:
                del file[key]
            return file

        else:
            file = YAML.ReadYaml(YAML.file_path).get(root)
            return file


if __name__ == '__main__':
    print(YAML.ReadRoot("redis"))
